package com.systop.service.impl;

import com.systop.mapper.BannerMapper;
import com.systop.pojo.Banner;
import com.systop.service.BannerService;
import com.systop.unti.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author zhangnan
 * @Data 2020/8/003 上午 10:00
 * @Descriiption
 **/
@Service
@Transactional
public class BannerServiceImpl implements BannerService {

    @Autowired
    private BannerMapper bannerMapper;
    //添加banner
    @Override
    public ResponseResult insertbanners(Banner banner) {
        Integer insertbanners = bannerMapper.insertbanners(banner);
        if (insertbanners!=null){
            return ResponseResult.ok(insertbanners);
        }else {
            return ResponseResult.build(400, "错误");
        }
    }
    //查询所有banner
    @Override
    public ResponseResult selectBannerAll() {
        List<Banner> list = bannerMapper.selectBannerAll();
        if (list!=null){
            return ResponseResult.ok(list);
        }else {
            return ResponseResult.build(400, "错误");
        }
    }
    //根据id查询banner（更新之前查询出来）
    @Override
    public ResponseResult selectBannerByid(Integer banner_id) {
        Banner banner = bannerMapper.selectBannerByid(banner_id);
        if (banner!=null){
            return ResponseResult.ok(banner);
        }else {
            return ResponseResult.build(400, "错误");
        }
    }

    @Override
    public ResponseResult updateBannerByid(Banner banner) {
        Integer integer = bannerMapper.updateBannerByid(banner);
        if (integer!=null){
            return ResponseResult.ok(integer);
        }else {
            return ResponseResult.build(400, "错误");
        }
    }

    @Override
    public ResponseResult deleteBannerByid(Integer banner_id) {
        Integer integer = bannerMapper.deleteBannerByid(banner_id);
        if (integer!=null){
            return ResponseResult.ok(integer);
        }else {
            return ResponseResult.build(400, "错误");
        }
    }

}

